#include "pch.h"
#include "IniConfig.h"
#include "StringUtils.h"

namespace Utils
{

	IniConfig::IniConfig()
	{
	}

	IniConfig::~IniConfig()
	{
	}

	bool IniConfig::SetValue(const std::string& filename, const std::string& section, const std::string& key, const std::string& value)
	{
		if (filename.empty() || section.empty() || key.empty())
		{
			return false;
		}

		if (!::WritePrivateProfileStringA(section.c_str(), key.c_str(), value.c_str(), filename.c_str()))
		{
			return false;
		}

		return true;
	}

	std::string IniConfig::GetValue(const std::string& filename, const std::string& section, const std::string& key, const std::string& defaultValue)
	{
		if (filename.empty() || section.empty() || key.empty())
		{
			return defaultValue;
		}


		char retVaue[512] = { 0 };
		if (::GetPrivateProfileStringA(section.c_str(), key.c_str(), NULL, retVaue, MAX_PATH, filename.c_str()) == 0)
		{
			return defaultValue;
		}

		return retVaue;
	}

}